package com.fufufu.mail.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.fufufu.mail.ware.vo.DoneVo;
import com.fufufu.mail.ware.vo.PurchaseMergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.fufufu.mail.ware.entity.PurchaseEntity;
import com.fufufu.mail.ware.service.PurchaseService;
import com.fufufu.common.utils.PageUtils;
import com.fufufu.common.utils.R;

import javax.annotation.Resource;


/**
 * 采购信息
 *
 * @author zyx
 * @email 1262074394@qq.com
 * @date 2022-09-15 08:22:47
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {

    @Resource
    private PurchaseService purchaseService;



    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查出订单状态为新建和已领取的订单，这些订单是可以将采购需求合并进去的
     */
    @GetMapping("/unreceive/list")
    public R unreceiveList(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryUnreceivePurchase(params);
        return R.ok().put("page", page);
    }

    @PostMapping("/receive")
    public R receive(@RequestBody List<Long> purchaseId) {
        purchaseService.receive(purchaseId);

        return R.ok();
    }

    @PostMapping("/merge")
    public R merge(@RequestBody PurchaseMergeVo purchaseMergeVo) {
        purchaseService.merge(purchaseMergeVo);

        return R.ok();
    }

    @PostMapping("/done")
    public R done(@RequestBody DoneVo doneVo) {

        purchaseService.done(doneVo);
        return R.ok();
    }
}
